package com.itheima.service;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    Logger logger = LoggerFactory.getLogger(UserService.class);
    @Autowired
    private UserMapper userMapper;

    public User queryUserById(Long id) {
        long start = System.currentTimeMillis();

        User user = this.userMapper.selectByPrimaryKey(id);

        try {
            Thread.sleep((int) Math.random() * 2000 + 1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endtime = System.currentTimeMillis();
        logger.info("本次查询的id是: {},耗时 {}毫秒", id, endtime - start);
        return user;

    }
}
